﻿<styles:ChromedWindow
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:designTime="clr-namespace:unTroublemakerUI.ViewModel.DesignTime"
        xmlns:viewModel="clr-namespace:unTroublemakerUI.ViewModel"
        xmlns:styles="clr-namespace:unTroublemakerUI.Styles"
        x:Class="unTroublemakerUI.MainWindow"
        mc:Ignorable="d"
        Title="MainWindow" 
        Height="350" 
        Width="525" 
        Icon="unTroublemaker.ico"
        SizeToContent="WidthAndHeight"
        WindowStyle="None"
        d:DataContext="{x:Static designTime:DesignTimeMainWindowViewModel.Instance}">

    <styles:ChromedWindow.Resources>

        <Style x:Key="StatusIcon" BasedOn="{StaticResource {x:Type styles:Icon}}" TargetType="{x:Type styles:Icon}">
            <Setter Property="RenderTransform">
                <Setter.Value>
                    <TranslateTransform X="0" Y="0" />
                </Setter.Value>
            </Setter>
            <Setter Property="Opacity" Value="0"/>
        </Style>

        <Storyboard x:Key="GoGreen">
            <ColorAnimation Storyboard.TargetProperty="(TextBlock.Foreground).(SolidColorBrush.Color)" To="Green" Duration="0:0:0.500"/>
            <DoubleAnimation Storyboard.TargetName="PassedIcon" From="0" To="1" Storyboard.TargetProperty="Opacity" Duration="0:0:0.500" />
            <DoubleAnimation Storyboard.TargetName="FailedIcon" To="0" Storyboard.TargetProperty="Opacity" Duration="0:0:0.500" />
            <DoubleAnimation Storyboard.TargetName="PassedIcon" From="-15" To="0" Storyboard.TargetProperty="RenderTransform.(TranslateTransform.Y)" Duration="0:0:0.500" />
            <ColorAnimation Storyboard.TargetName="PassedIcon" Storyboard.TargetProperty="(Fill).(SolidColorBrush.Color)" To="White" Duration="0:0:0.500" BeginTime="0:0:0.500" />
            <ColorAnimation Storyboard.TargetName="PassedIcon" Storyboard.TargetProperty="(Stroke).(SolidColorBrush.Color)" To="White"  Duration="0:0:0.500" BeginTime="0:0:0.500" />
            <ColorAnimation Storyboard.TargetName="IconBorder" Storyboard.TargetProperty="(Background).(SolidColorBrush.Color)" To="DarkGreen"  Duration="0:0:0.500" BeginTime="0:0:0.500" />
        </Storyboard>

        <Storyboard x:Key="GoRed">
            <ColorAnimation Storyboard.TargetProperty="(TextBlock.Foreground).(SolidColorBrush.Color)" To="Red" Duration="0:0:0.500"/>
            <DoubleAnimation Storyboard.TargetName="FailedIcon" From="0" To="1" Storyboard.TargetProperty="Opacity" Duration="0:0:0.500" />
            <DoubleAnimation Storyboard.TargetName="PassedIcon" To="0" Storyboard.TargetProperty="Opacity" Duration="0:0:0.500" />
            <DoubleAnimation Storyboard.TargetName="FailedIcon" From="-15" To="0" Storyboard.TargetProperty="RenderTransform.(TranslateTransform.Y)" Duration="0:0:0.500" />
            <ColorAnimation Storyboard.TargetName="FailedIcon" Storyboard.TargetProperty="(Stroke).(SolidColorBrush.Color)" To="White"  Duration="0:0:0.500" BeginTime="0:0:0.500" />
            <ColorAnimation Storyboard.TargetName="FailedIcon" Storyboard.TargetProperty="(Fill).(SolidColorBrush.Color)" To="White"  Duration="0:0:0.500" BeginTime="0:0:0.500" />
            <ColorAnimation Storyboard.TargetName="IconBorder" Storyboard.TargetProperty="(Background).(SolidColorBrush.Color)" To="DarkRed"  Duration="0:0:0.500" BeginTime="0:0:0.500" />
        </Storyboard>
       
        <ControlTemplate x:Key="ButtonBaseControlTemplate1" TargetType="{x:Type ButtonBase}">
            <Border Name="Box"  BorderThickness="{TemplateBinding BorderThickness}" BorderBrush="{TemplateBinding BorderBrush}" Padding="{TemplateBinding Padding}" Background="{TemplateBinding Background}">
                <ContentPresenter ContentTemplate="{TemplateBinding ContentTemplate}" Content="{TemplateBinding Content}" ContentStringFormat="{TemplateBinding ContentStringFormat}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
            </Border>
            <ControlTemplate.Triggers>
                <Trigger Property="IsMouseOver" Value="True">
                    <Trigger.EnterActions>
                        <BeginStoryboard>
                            <Storyboard>
                                <ColorAnimation Storyboard.TargetName="Box" Storyboard.TargetProperty="Background.(SolidColorBrush.Color)"
                                                To="DarkGray" Duration="0:0:0.200"/>
                                <ColorAnimation Storyboard.TargetProperty="Foreground.(SolidColorBrush.Color)"
                                                To="White" Duration="0:0:0.200"/>
                            </Storyboard>
                        </BeginStoryboard>
                    </Trigger.EnterActions>
                    <Trigger.ExitActions>
                        <BeginStoryboard>
                            <Storyboard>
                                <ColorAnimation Storyboard.TargetName="Box" Storyboard.TargetProperty="Background.(SolidColorBrush.Color)"
                                                To="WhiteSmoke" Duration="0:0:0.200"/>
                                <ColorAnimation Storyboard.TargetProperty="Foreground.(SolidColorBrush.Color)"
                                                To="Black" Duration="0:0:0.200"/>
                            </Storyboard>
                        </BeginStoryboard>
                    </Trigger.ExitActions>
                </Trigger>
                
                <Trigger Property="IsKeyboardFocused" Value="True">
                </Trigger>
                <Trigger Property="ToggleButton.IsChecked" Value="True">
                    
                </Trigger>
                <Trigger Property="IsEnabled" Value="False">
                    <Setter Property="Foreground" Value="#FFADADAD"/>
                </Trigger>
            </ControlTemplate.Triggers>
        </ControlTemplate>
        
        <Style TargetType="Button">
            <Setter Property="Template" Value="{StaticResource ButtonBaseControlTemplate1}"/>
            <Setter Property="Padding" Value="10, 0"/>
            <Setter Property="Background" Value="WhiteSmoke"/>
            <Setter Property="Foreground" Value="Black"/>
        </Style>
        
    </styles:ChromedWindow.Resources>

    <styles:ChromedWindow.Style>
        <StaticResource ResourceKey="ChromedWindowStyle"/>
    </styles:ChromedWindow.Style>

    <styles:ChromedWindow.DataContext>
        <viewModel:MainWindowViewModel />
    </styles:ChromedWindow.DataContext>

    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>

        <Grid Grid.Row="0">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*"/>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="Auto"/>
            </Grid.ColumnDefinitions>

            <TextBox Text="{Binding SpecificationPath}" Grid.Column="0" VerticalAlignment="Center" Margin="5"/>
            <Button Command="{Binding BrowseCommand}"  Margin="5" Grid.Column="1" Template="{DynamicResource ButtonBaseControlTemplate1}" Content="Browse"/>
            <Button Command="{Binding RunCommand}" Margin="5" Grid.Column="2">
                <StackPanel Orientation="Horizontal">
                    <TextBlock Text="Run" VerticalAlignment="Center" />
                    <styles:Icon Path="{StaticResource IconRun}" Margin="10,0,0,0" Fill="{Binding Path=Foreground, RelativeSource={RelativeSource Mode=Self}}" Stroke="{Binding Path=Foreground, RelativeSource={RelativeSource Mode=Self}}" VerticalAlignment="Center" />
                </StackPanel>
            </Button>
        </Grid>

        <Grid Margin="5" Grid.Row="1">
            <TextBox IsReadOnly="True" Visibility="{Binding HasError, Converter={StaticResource BoolToVisibilityConverter}}" Text="{Binding ErrorMessage}"/>
            <TreeView PreviewMouseWheel="ScrollTree" Background="Transparent" ItemsSource="{Binding SpecificationItems}" Visibility="{Binding HasError, Converter={StaticResource InverseBoolToVisibilityConverter}}" BorderThickness="0">
                <TreeView.ItemTemplate>
                    <HierarchicalDataTemplate DataType="{x:Type viewModel:ISpecificationItemViewModel}" ItemsSource="{Binding SubItems}">
                        <StackPanel Orientation="Horizontal" Margin="2">
                            <Border x:Name="IconBorder" BorderBrush="Black" BorderThickness="1" CornerRadius="2,0,0,2" Padding="1" Background="White">
                                <Grid>
                                    <styles:Icon Path="{StaticResource IconCheck}" x:Name="PassedIcon" Style="{StaticResource StatusIcon}" Stroke="Green" Fill="Green" />
                                    <styles:Icon Path="{StaticResource IconWarning}" x:Name="FailedIcon" Style="{StaticResource StatusIcon}" Stroke="Red" Fill="Red" />
                                </Grid>
                            </Border>
                            <Border Background="White" BorderBrush="Black" BorderThickness="0,1,1,1" CornerRadius="0,2,2,0" Padding="1">
                                <TextBlock Margin="5,0,10,1" Text="{Binding DisplayName}" x:Name="Label" Foreground="Black" VerticalAlignment="Center"/>
                            </Border>
                        </StackPanel>
                        <HierarchicalDataTemplate.Triggers>
                            <DataTrigger Binding="{Binding Failed}" Value="true">
                                <DataTrigger.EnterActions>
                                    <BeginStoryboard Storyboard="{StaticResource GoRed}"/>
                                </DataTrigger.EnterActions>
                            </DataTrigger>
                            <DataTrigger Binding="{Binding Passed}" Value="true">
                                <DataTrigger.EnterActions>
                                    <BeginStoryboard Storyboard="{StaticResource GoGreen}"/>
                                </DataTrigger.EnterActions>
                            </DataTrigger>
                        </HierarchicalDataTemplate.Triggers>
                    </HierarchicalDataTemplate>
                </TreeView.ItemTemplate>
                <TreeView.ItemContainerStyle>
                    <Style TargetType="{x:Type TreeViewItem}">
                        <Setter Property="IsExpanded" Value="{Binding Expanded}"/>
                    </Style>
                </TreeView.ItemContainerStyle>
            </TreeView>
        </Grid>

        <!--<ProgressBar Height="18" Grid.Row="2" Maximum="{Binding ItemCount}" Value="{Binding ItemsProcessed}" Visibility="{Binding IsRunning, Converter={StaticResource BoolToVisibilityConverter}}" Margin="5" />-->

    </Grid>
</styles:ChromedWindow>
